/// <reference name="MicrosoftAjax.js" path="../MicrosoftAjax.js" />
/// <reference name="jquery-1.4.4-vsdoc.js" path="../jquery-1.4.4-vsdoc.js" />


(function (n) {
    var $to = n.$to = new Object();


    $to.ajax = function (options) {
        if (typeof (options.type) == 'undefined') {
            options.type = 'POST';
        }
        if (typeof (options.cache) == 'undefined') {
            options.cache = false;
        }
        if (typeof (options.async) == 'undefined') {
            options.async = true;
        }
        if (typeof (options.error) == 'undefined') {
            options.error = function (response, status, xhr) {
                window.location.href = ResolveWindowUrl('~/Error');
            }
        }

        $.ajax(options);
    };
})(window);


(function (n) {

    n.BaseUrl = '';
    n.FullSiteUrl = '';
    n.ResolveUrl = function (url) {
        if (url.indexOf("~/") == 0) {
            var baseUrl = '';
            if (FullSiteUrl == '') {
                baseUrl = document.location.protocol + "//" + document.location.host + n.BaseUrl;
            }
            else {
                baseUrl = FullSiteUrl;
            }
            if (baseUrl[baseUrl.length-1] == '/')
            {
                url = baseUrl+ url.substring(2);
            }
            else{
                url = baseUrl+'/' + url.substring(2);
            }
        }
        return encodeURI(url);
    };
})(window)

window.onerror = function (errorMessage, url, line) {
    var parameters = "?description=" + escape(errorMessage)
      + "&url=" + escape(url)
      + "&line=" + escape(line)
      + "&parent_url=" + escape(document.location.href)
      + "&user_agent=" + escape(navigator.userAgent);

    $.get(ResolveUrl('~/Error/Log' + parameters));
    alert(errorMessage);
};